<?php
$pegawai = array();

foreach($data->result_array() as $row)
$pegawai = $row;
?>

	<!-- BEGIN PAGE -->
	<div class="page-content">
         <!-- BEGIN PAGE CONTAINER-->        
         <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->
			<div class="row-fluid">
				<div class="span12"> 
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->			
					<h3 class="page-title">
						Form Pegawai <small> menambah dan mengedit pegawai</small>
					</h3>
					<ul class="breadcrumb">
						<li>
							<i class="icon-cogs"></i>
							Pengaturan Awal		
							<i class="icon-angle-right"></i>
						</li>
						<li>
							<a href="<?php echo base_url()?>pegawai">Pegawai</a>		
							<i class="icon-angle-right"></i>
						</li>
						<li>Form Pegawai</li>	
					</ul>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->          
            <div class="row-fluid">
				
               <div class="span12">
                  <!-- BEGIN SAMPLE TABLE PORTLET-->
                  <div class="portlet box green">
                     <div class="portlet-title">
                        <div class="caption"><i class="icon-cogs"></i>Form Pegawai</div>
                     </div>
                     <div class="portlet-body form">
                        <!-- BEGIN FORM-->
						<form id="form-pegawai" action="" class="form-horizontal form-bordered form-row-stripped" action="<?php echo base_url()."pegawai/form/".(isset($pegawai['pegawai_id'])?encode($pegawai['pegawai_id']):'')?>" method="post" enctype="multipart/form-data">  
						<div class="row-fluid">
							<div class="span9">
								<div class="control-group">
									<label class="control-label">Bagian</label>
									  <div class="controls">
										 <select class="span6 m-wrap large" name="data[bagian_pegawai_id]" data-placeholder="Choose a Category" tabindex="1">
											<option value="">------- Pilih Bagian -------</option>
											<?php foreach($bagian_pegawai->result_array() as $row){?>
											 <option value="<?php echo $row['bagian_pegawai_id']?>" <?php echo isset($pegawai['bagian_pegawai_id']) && $pegawai['bagian_pegawai_id'] == $row['bagian_pegawai_id']?'selected="selected"':''?>><?php echo $row['bagian']?></option>
											<?php } ?>
										</select>
									</div>
								</div>
								<div class="control-group">
									<label class="control-label" for="firstName">NIP</label>
									<div class="controls">
									   <input type="text" id="nip" name="data[nip]" value="<?php echo isset($pegawai['nip'])?$pegawai['nip']:''?>" class="m-wrap span8" placeholder="Masukkan NIP" required>
									</div>
								 </div>
								<div class="control-group">
								<label class="control-label" for="lastName">Nama</label>
								<div class="controls">
								   <input type="text" id="nama" name="data[nama]" value="<?php echo isset($pegawai['nama'])?$pegawai['nama']:''?>" class="m-wrap span8 popovers" data-trigger="hover" data-content="hai" placeholder="Masukkan Nama" required>
								</div>
							 </div>
									<div class="control-group">
							   <label class="control-label" for="lastName">Panggilan</label>
								<div class="controls">
								   <input type="text" id="panggilan" name="data[panggilan]" value="<?php echo isset($pegawai['panggilan'])?$pegawai['panggilan']:''?>" class="m-wrap span8" placeholder="Masukkan Panggilan" required>
								</div>
							</div>
									<div class="control-group">
								<label class="control-label" for="lastName">Gelar</label>
								<div class="controls">
								   <input type="text" id="gelar" name="data[gelar]" value="<?php echo isset($pegawai['gelar'])?$pegawai['gelar']:''?>" class="m-wrap span4" placeholder="Masukkan Gelar">
								</div>
							 </div>
								</div>
								<div class="span3">
									<div class="control-group">
										 <div class="fileupload fileupload-new" data-provides="fileupload" style="margin-top:10px;">
											<div class="fileupload-new thumbnail" style="width: 200px; height: 265px;">
												<?php if(isset($pegawai['foto'])){?>
												<img src="<?php echo 'data:image/png;base64,'.base64_encode($pegawai['foto'])?>" alt="" />
												<?php }else{?>
											   <img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&amp;text=no+image" alt="" />
											   <?php } ?>
											</div>
											<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
											<div>
											   <input type="file" name="userfile" class="default" /></span>
											</div>
										 </div>	
									  </div>
								</div>
							</div>
							<div class="control-group">
								  <label class="control-label">Jenis Kelamin</label>
								  <div class="controls">
									 <label class="radio">
									 <input type="radio" name="data[kelamin]" value="L"  <?php echo (isset($pegawai['kelamin']) &&  $pegawai['kelamin'] == "L")?'checked="checked"':''?> checked />
									 Laki-laki
									 </label>
									 <label class="radio">
									 <input type="radio" name="data[kelamin]" value="P" <?php echo (isset($pegawai['kelamin']) &&  $pegawai['kelamin'] == 
									 "P")?'checked="checked"':''?> />
									 Perempuan
									 </label>                                
								  </div>
							   </div> 
							 <div class="control-group">
								<label class="control-label" for="lastName">Tempat Lahir</label>
								<div class="controls">
								   <input type="text" id="tmp_lahir" name="data[tmp_lahir]" value="<?php echo isset($pegawai['tmp_lahir'])?$pegawai['tmp_lahir']:''?>" class="m-wrap span4" placeholder="Masukkan Tempat Lahir">
								</div>
							 </div>             
							 <div class="control-group">
								<label class="control-label" >Tanggal Lahir</label>
								<div class="controls">    
									<?php
										if(isset($pegawai['tgl_lahir'])){
											$date = explode("-",$pegawai['tgl_lahir']);
										}else{
											$date = explode("-",date("Y-m-d"));
										}
									?>
								   <select id="day" name="day" class="span2 m-wrap select2">
									<?php for($i=1;$i<32;$i++){?>
									<option value="<?php echo $i<10?"0$i":$i?>" <?php echo (int)$date[2] == (int)$i?'selected="selected"':''?>><?php echo $i<10?"0$i":$i?></option>
									<?php } ?>
								 </select>
								 <select id="month" name="month" class="span3 m-wrap select2">
									<?php foreach(bulans() as $key=>$value){?>
									<option value="<?php echo ($key+1) < 10?"0".($key+1):$key+1?>" <?php echo $date[1] == $key+1?'selected="selected"':''?>><?php echo $value?></option>
									<?php } ?>
								 </select>
								 <select id="year" name="year" class="span3 m-wrap select2">
									<?php
									$year = date("Y")-80;
									for($i=0;$i<=80;$i++){
									?>
									<option value="<?php echo $year+$i?>" <?php echo $date[0] == $year+$i?'selected="selected"':''?>><?php echo $year+$i?></option>
									<?php } ?>
								 </select>
								 <a href="#" class="btn" id="btn-date" data-date-format="yyyy-mm-dd"><i class="icon-calendar"></i> Kalender</a>
								
								<script>
									$(document).ready(function(){
										$('#btn-date').datepicker()
											.on('show', function(ev){
												var date = $("#year").val()+"-"+$("#month").val()+"-"+$("#day").val();
												$('#btn-date').data({date: date});
												$('#btn-date').datepicker('update');
											})
											.on('changeDate', function(ev){
												$('#btn-date').datepicker('hide');
												
												var date = new Date(ev.date);
												var month = date.getMonth()+1;
												var mth = "";
												if(month < 10){
													mth = "0"+month;
												}
												
												$("#year").select2("val", date.getFullYear());
												$("#month").select2("val", mth);
												$("#day").select2("val", date.getDate());
											});
									})
								</script> 
								</div>
							 </div>	 
							 <div class="control-group">
							  <label class="control-label">Agama</label>
								  <div class="controls">
									 <select class="span6 m-wrap large" name="data[agama_id]" data-placeholder="" tabindex="1">
										<option value="">------- Pilih Agama -------</option>
										<?php foreach($agama->result_array() as $row){?>
										 <option value="<?php echo $row['agama_id']?>" <?php echo isset($pegawai['agama_id']) && $pegawai['agama_id'] == $row['agama_id']?'selected="selected"':''?>><?php echo $row['agama']?></option>
										<?php } ?>
									</select>
								</div>
							</div>                                    
							 <div class="control-group">
								<label class="control-label">Suku</label>
								  <div class="controls">
									 <select class="span6 m-wrap large" name="data[suku_id]" data-placeholder="Choose a Category" tabindex="1">
										<option value="">------- Pilih Suku -------</option>
										<?php foreach($suku->result_array() as $row){?>
										 <option value="<?php echo $row['suku_id']?>" <?php echo isset($pegawai['suku_id']) && $pegawai['suku_id'] == $row['suku_id']?'selected="selected"':''?>><?php echo $row['suku']?></option>
										<?php } ?>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" >Menikah</label>
								<div class="controls">
								<?php
									$status = array(
										1 => "Sudah",
										2 => "Belum",
										3 => "Tidak ada"
									);									
								?>
								   <select  class="span6 m-wrap large" id="nikah" name="data[nikah]" >
									  <option value="">------- Pilih Status -------</option>
									  <?php foreach($status as $key=>$value){?>
									  <option value="<?php echo $key?>" <?php echo isset($pegawai['nikah']) && $pegawai['nikah'] == $key?'selected="selected"':''?>><?php echo $value?></option>
										 <?php } ?>
								   </select>
								</div>
							 </div>      
							 <div class="control-group">
								<label class="control-label" for="firstName">No Identitas</label>
								<div class="controls">
								   <input type="text" id="no_id" name="data[no_id]" value="<?php echo isset($pegawai['no_id'])?$pegawai['no_id']:''?>" class="m-wrap span6" placeholder="Masukkan no identitas">
								</div>
							 </div>
						   <div class="control-group">
							  <label class="control-label">Alamat</label>
							  <div class="controls">
								 <textarea class="span6 m-wrap" name="data[alamat]" rows="3"><?php echo isset($pegawai['alamat'])?$pegawai['alamat']:''?></textarea>
							  </div>
						   </div>   
							 <div class="control-group">
								<label class="control-label" for="firstName">Telepon</label>
								<div class="controls">
								   <input type="text" id="telpon" name="data[telpon]" value="<?php echo isset($pegawai['telpon'])?$pegawai['telpon']:''?>" class="m-wrap span6" placeholder="Masukkan Telepon">
								</div>
							 </div>
							 <div class="control-group">
								<label class="control-label" for="lastName">Handphone</label>
								<div class="controls">
								   <input type="text" id="handphone" name="data[handphone]" value="<?php echo isset($pegawai['handphone'])?$pegawai['handphone']:''?>" class="m-wrap span6" placeholder="Masukkan Handphone">
								</div>
							 </div>          
							 <div class="control-group">
								<label class="control-label" for="firstName">Email</label>
								<div class="controls">
								   <input type="text" id="email" name="data[email]" value="<?php echo isset($pegawai['email'])?$pegawai['email']:''?>" class="m-wrap span6" placeholder="Masukkan Email">
								</div>
							 </div>					   
								 
								<div class="control-group">
								  <label class="control-label">Keterangan</label>
								  <div class="controls">
									 <textarea class="span6 m-wrap" name="data[keterangan]" rows="3"><?php echo isset($pegawai['keterangan'])?$pegawai['keterangan']:''?></textarea>
								  </div>
							   </div>
							  <div class="control-group">
								  <label class="control-label">Aktif</label>
								  <div class="controls">
									 <label class="radio">
									 <input type="radio" name="data[aktif]" value=1  <?php echo (isset($pegawai['aktif']) &&  $pegawai['aktif'] == 1)?'checked="checked"':''?> checked />
									 Ya
									 </label>
									 <label class="radio">
									 <input type="radio" name="data[aktif]" value=0 <?php echo (isset($pegawai['aktif']) &&  $pegawai['aktif'] == 0)?'checked="checked"':''?> />
									 Tidak
									 </label>                                
								  </div>
							   </div>
								                       
								<div class="form-actions">
								   <button type="submit" class="btn blue"><i class="icon-ok"></i> Simpan</button>
								   <a href="<?php echo base_url()?>pegawai" type="button" class="btn">Batal</a>
								</div>
					</form>
                                 <!-- END FORM--> 
			 </div>
		  </div>
                  <!-- END SAMPLE TABLE PORTLET-->
	   </div>				
	</div>
           
            <!-- END PAGE CONTENT-->
         </div>
         <!-- END PAGE CONTAINER-->
    </div>
    <!-- END PAGE -->
	<script>
		$(document).ready(function(){
			$("#form-pegawai").validate(
				{
					errorElement: 'span', //default input error message container
					errorClass: 'help-inline', // default input error message class
					focusInvalid: false, // do not focus the last invalid input
					ignore: "",
					highlight: function (element) { // hightlight error inputs
						$(element)
							.closest('.help-inline').removeClass('ok'); // display OK icon
						$(element)
							.closest('.control-group').removeClass('success').addClass('error'); // set error class to the control group
					},

					unhighlight: function (element) { // revert the change dony by hightlight
						$(element)
							.closest('.control-group').removeClass('error'); // set error class to the control group
					},

					success: function (label) {
						label
							.addClass('valid').addClass('help-inline ok') // mark the current input as valid and display OK icon
						.closest('.control-group').removeClass('error').addClass('success'); // set success class to the control group
					}
				}
			);
			
			$('.select2').select2();
		});
	</script>
	<?php $this->load->view('template/messages'); ?>
